<template>
    <page-meta :page-style="'overflow:'+(showPop?'hidden':'visible')"></page-meta>
    <view class="c-position_relative">
        <view class="header" style="margin-bottom: 30rpx;" v-if='false'>
            <view class="header c-position_fixed">
                <image class="bg-image" src="/static/images/index/index-bg.jpg" mode="aspectFill"></image>
            </view>
        </view>
        <template v-if="showPageEmpty">
            <c-empty type='lg'></c-empty>
        </template>
        <template v-else>
            <view class="item c-flex_column" v-for="(item, index) in pageData" :key="item.id">
                <list-item :lesson='item' @tapItem='tapItem'></list-item>
            </view>
            <uni-load-more :status="loadMoreStatusValue" :contentText="loadMoreBarContentText"
                iconType="snow"></uni-load-more>
        </template>
        <unit-list-pop ref="unitListPop" @show='unitListShow'></unit-list-pop>
    </view>
</template>

<script>
    import {
        getLessonList
    } from "./services/index.js"
    import listItem from "./components/list-item.vue";
    import unitListPop from "./components/unit-list-pop.vue";
    import PageQueryMixin from "../../common/mixins/page-query-mixin.js";
    import LessonItemModel from "./models/lessonItemModel";
    import {
        checkAll
    } from "../../common/services/index.js"
    export default {
        mixins: [PageQueryMixin],
        components: {
            listItem,
            unitListPop
        },
        data() {
            return {
                showPop: false
            };
        },
        onReady() {
            uni.startPullDownRefresh({

            })
        },
        onPullDownRefresh() {
            this.pageRefreshFn();
        },
        onReachBottom() {
            this.pageLoadMoreFn();
        },
        methods: {
            overLoadPageRequest(pageNo, pageSize) {
                // 请求课程列表数据
                return getLessonList(pageNo, pageSize);
            },
            overLoadPageRequestSuccess(res) {
                // 请求成功处理
                this.pageTotalCount = res.total;
                let data = res.records.map((item, index) => {
                    return new LessonItemModel({
                        ...item,
                        index: index + this.pageData.length
                    })
                })
                this.pageData = [...this.pageData, ...data]
            },
            overLoadPageRequestFinally(res) {
                // 请求完成处理
                uni.stopPullDownRefresh();
            },
            tapItem(item) {
                checkAll(item.promise).then(res => {
                    this.$refs.unitListPop.show(true, item);
                })
            },
            unitListShow(show) {
                this.showPop = show;
            }
        }
    }
</script>

<style lang="scss" scoped>
    .header {
        width: 100%;
        height: 450rpx;
        z-index: 4;

        .bg-image {
            width: 100%;
            height: 100%;
        }
    }

    .item {
        margin: 70rpx 15rpx;
        margin-bottom: 0;
    }

    .item:last-child {
        margin-bottom: 70rpx;
    }
</style>